package balking;

import java.util.Random;

public class ChangeThread extends Thread {

    private final Data data;

    public ChangeThread(String name, Data data) {
        super(name);
        this.data = data;
    }

    @Override
    public void run() {
        int i = 0;
        while (true) {
            i++;
            data.change(super.getName() , "内容：" + i);
            try {
                Thread.sleep(new Random().nextInt(1000));
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            try {
                data.save(super.getName());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
